<template>
	<view class="login">
		<view class="box">
			<image src="../../static/images/qz.png" mode="aspectFit"></image>
			<p>空港卡券联盟</p>
		</view>
		<!-- <p>申请获得你的公开信息(昵称 头像等)</p> -->
		<u-checkbox-group class="u-checkbox-group">
			<u-checkbox class="u-checkbox" @change="checkboxChange" v-model="item.checked" v-for="(item, index) in list" :key="index">
				
			</u-checkbox>
			<text class="text-one">已阅读并同意此</text>
			<text @click="getUserServiceAgreement">服务协议</text>
		</u-checkbox-group>
		<button :disabled="disabled2" type="button" @click="logingo" :class="state == 1 ? 'active' : 'noActive'">微信用户一键登录</button>
		<u-modal v-model="show" v-html="content" :content="content" :title="title" :content-style="{padding: '30rpx'}"></u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {shareMixins} from '../../mixins/share.js'
	export default {
		mixins:[shareMixins],
		data() {
			return {
				shareData: {
				    title: '空港卡券联盟客户端',
				    path: '/pages/index/index' // 分享的页面路径
				},
				code: '', // 自己的code
				userInfo: '',
				list: [{
					name: '已阅读并同意此',
					checked: false,
					disabled: false
				}],
				title:'',
				show: false,
				content:'',
				disabled2: true,
				state:0
			}
		},
		onLoad() {},
		methods: {
			logingo() {
				var _this = this
				uni.getUserProfile({
					desc: '使用',
					lang: 'zh_CN',
					success(res) {
						if (res.userInfo) {
							_this.userInfo = res.userInfo
							uni.setStorageSync('loginuserInfo', res.userInfo)
							uni.login({
								provider: 'weixin',
								success: (res) => {
									uni.request({
										url: 'https://ca.wupin.shop/api/user/wechatLogin?code=' +
											res.code,
										method: 'GET',
										success: (res) => {
											uni.setStorageSync('openid', res.data.data
												.openid)
											uni.request({
												url: 'https://ca.wupin.shop/api/user/wechatInfoSave',
												method: 'POST',
												data: {
													openid: res.data.data.openid,
													avatarUrl: _this.userInfo
														.avatarUrl,
													nickname: _this.userInfo
														.nickName,
													province: _this.userInfo
														.province
												},
												header: {
													'Content-Type': 'application/json', //请求头信息
													openid: res.data.data.openid
												},
												success: (res) => {
													if (res.data.code ===
														200) {
														uni.reLaunch({
															url: '../index/index'
														})
													} else {
														this.$refs.uToast
															.show({
																title: '登录失败',
																type: 'error'
															})
													}
												}
											});
										}
									});

								}
							});
						}
					},
					fail(err) {
						// console.log(err)
						// console.log('拒绝了授权')
						uni.showModal({
							title: '提示',
							content: '拒绝后无法正常浏览',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定');
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					}
				})
			},
			// 选中某个复选框时，由checkbox时触发
			checkboxChange(e) {
				console.log(e);
				if(e.value === true){
					this.disabled2 = false
					this.state = 1
				}else{
					this.disabled2 = true
					this.state = 0
				}
			},
			async getUserServiceAgreement(){//获取服务协议
				const res = this.$myRequest({
					url:'/api/common/getUserServiceAgreement'
				}).then((res) => {
					// console.log(res.data.data.setting_content)
					this.show = true
					this.content = res.data.data.setting_content
					this.title = res.data.data.setting_key
				})
			}
		},
	}
</script>

<style lang="scss">
	.login {
		.u-checkbox-group{
			margin-top: 50rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			.u-checkbox{
				margin: 0;
				padding: 0;
			}
			text{
				font-size: 30rpx;
				color: #2B85E4;
			}
			.text-one{
				margin-left: -20rpx;
				margin-right: 10rpx;
				font-size: 30rpx;
				color: #333333;
			}
		}
		
		.box {
			width: 260rpx;
			height: auto;
			margin: auto;
			margin-top: 200rpx;
			text-align: center;

			image {
				width: 163rpx;
				height: 130rpx;
				margin-bottom: 22rpx;
			}

			p {
				font-size: 40rpx;
				color: #3C3C3C;

			}
		}

		.active {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 80%;
			height: 100rpx;
			background: linear-gradient(#FFB487, #EC5F2F);
			border-radius: 100rpx;
			color: #FFFFFF;
			font-size: 36rpx;
			margin-top: 20rpx;
		}
		.noActive {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 80%;
			height: 100rpx;
			background: linear-gradient(#BCBCBC, #808080);
			border-radius: 100rpx;
			color: #FFFFFF;
			font-size: 36rpx;
			margin-top: 20rpx;
		}
	}
</style>
